﻿using System;
using System.Collections.Generic;
using System.Collections;
using Inovout.Business;

namespace Inovout.Gui.Wpf
{
    public class ViewDataDictionary : IDictionary<string, object>,IViewDataDictionary
    {

        public ViewDataDictionary()
        {
        }
        private readonly Dictionary<string, object> innerDictionary = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
        private object model;

        public  ViewDataDictionary(IViewDataDictionary dictionary,object model)
        {
            foreach (var entry in (ViewDataDictionary)dictionary)
            {
                innerDictionary.Add(entry.Key, entry.Value);
            }
            Model = model;
        }

        public ViewDataDictionary(IViewDataDictionary dictionary)
        {
            foreach (var entry in (ViewDataDictionary)dictionary)
            {
                innerDictionary.Add(entry.Key, entry.Value);
            }
            Model = dictionary.Model;
     
        }

        public int Count
        {
            get
            {
                return innerDictionary.Count;
            }
        }

        public bool IsReadOnly
        {
            get
            {
                return ((IDictionary<string, object>)innerDictionary).IsReadOnly;
            }
        }

        public ICollection<string> Keys
        {
            get
            {
                return innerDictionary.Keys;
            }
        }

        public object Model
        {
            get
            {
                return model;
            }
            set
            {
                SetModel(value);
            }
        }
        protected virtual void SetModel(object value)
        {
            model = value;
        }

        public object this[string key]
        {
            get
            {
                object value;
                innerDictionary.TryGetValue(key, out value);
                return value;
            }
            set
            {
                innerDictionary[key] = value;
            }
        }



        public ICollection<object> Values
        {
            get
            {
                return innerDictionary.Values;
            }
        }

        public void Add(KeyValuePair<string, object> item)
        {
            ((IDictionary<string, object>)innerDictionary).Add(item);
        }

        public void Add(string key, object value)
        {
            innerDictionary.Add(key, value);
        }

        public void Clear()
        {
            innerDictionary.Clear();
        }

        public bool Contains(KeyValuePair<string, object> item)
        {
            return ((IDictionary<string, object>)innerDictionary).Contains(item);
        }

        public bool ContainsKey(string key)
        {
            return innerDictionary.ContainsKey(key);
        }

        public void CopyTo(KeyValuePair<string, object>[] array, int arrayIndex)
        {
            ((IDictionary<string, object>)innerDictionary).CopyTo(array, arrayIndex);
        }

        public IEnumerator<KeyValuePair<string, object>> GetEnumerator()
        {
            return innerDictionary.GetEnumerator();
        }

        public bool Remove(KeyValuePair<string, object> item)
        {
            return ((IDictionary<string, object>)innerDictionary).Remove(item);
        }

        public bool Remove(string key)
        {
            return innerDictionary.Remove(key);
        }

        public bool TryGetValue(string key, out object value)
        {
            return innerDictionary.TryGetValue(key, out value);
        }

     
        IEnumerator IEnumerable.GetEnumerator()
        {
            return innerDictionary.GetEnumerator();
        }


    }

}
